package cn.water.rocketmq.sequence;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.MessageQueueSelector;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;
import org.junit.Test;

import java.nio.charset.StandardCharsets;
import java.util.List;

public class SequenceProducer {
    @Test
    public void sequenceProducer() throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer();
        producer.setNamesrvAddr("localhost:9876");
        producer.setProducerGroup("sequence-group");
        producer.start();
        Message message = new Message();
        message.setTopic("sequence-topic");
        message.setTags("tagA");
        message.setKeys("KEY");
        message.setBody(("HELLO ROCKETMQ 我是风一样的男人").getBytes(StandardCharsets.UTF_8));
        SendResult result = producer.send(message, new MessageQueueSelector() {
            @Override
            public MessageQueue select(List<MessageQueue> list, Message message, Object o) {
                return list.get(0);
            }
        },3);
        System.out.println("result:"+result);
        producer.shutdown();
        }

}

